package test8;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(101, "张三", 260));
        list.add(new Student(102, "李四", 160));
        list.add(new Student(103, "王五", 180));
        list.add(new Student(104, "赵六", 190));
        for (Student student : list) {
            System.out.println(student.getId()+"\t"+student.getName()+"\t"+student.getScore());
        }
        // 排序,使用lambda表达式简写
        list.sort((s1,s2)->s2.getScore()-s1.getScore());

        //指定索引位置添加
        list.add(2,new Student(105, "小王", 170));
        System.out.println("添加后的学生信息：");
        for (Student student : list) {
            System.out.println(student.getId()+"\t"+student.getName()+"\t"+student.getScore());
        }
        //指定索引删除
        list.remove(0);
        list.sort((s1,s2)->s2.getScore()-s1.getScore());
        System.out.println("删除后的学生信息");
        for (Student student : list) {
            System.out.println(student.getId()+"\t"+student.getName()+"\t"+student.getScore());
        }

    }
}
